package com.ktg.mes.dv.domain;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.experimental.Accessors;

import com.ktg.common.annotation.Excel;
import com.ktg.common.core.domain.BaseEntity;


/**
 * 电表数据对象 dv_watt_hour_meter_data
 *
 * @author byteco
 * @date 2022-11-30
 */

@Data
@Accessors(chain = true)
@TableName("dv_watt_hour_meter_data")
public class DvWattHourMeterData extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 工序项id */
    @TableId(value = "record_id", type = IdType.AUTO)
    @JsonFormat(shape = JsonFormat.Shape.STRING) //转化成string传到前端
    private Long recordId;


    /** 生产关联（排产任务，生产设备，工序） */
    @Excel(name = "生产关联", readConverterExp = "排=产任务，生产设备，工序")
    private Long taskDeviceProcessRecordId;


    /** 任务id */
    @Excel(name = "任务id")
    private String taskId;

    /** 任务id */
    @Excel(name = "任务名称")
    private String taskName;

    /** 批次 */
    @Excel(name = "批次")
    private String batchNo;


    /** 设备id */
    @Excel(name = "设备id")
    private Long deviceId;


    /** 设备id */
    @Excel(name = "设备id")
    private String deviceCode;


    /** 设备id */
    @Excel(name = "设备id")
    private String deviceName;


    /** 工序项ID */
    @Excel(name = "工序项ID")
    private Long processId;


    /** 工序项名称 */
    @Excel(name = "工序项名称")
    private String processName;

    /** 运行时间 */
    @Excel(name = "运行时间")
    private Integer runtime;


    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Double va;


    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Double vb;


    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Double vc;


    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Double ia;


    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Double ib;


    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Double ic;


    /** 度数 */
    @Excel(name = "度数")
    private Double zxygzdl;


    /** 大于等于1代表启动中 */
    @Excel(name = "大于等于1代表启动中")
    private Double zszgl;


    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Double zglys;


    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Double hz;



    public void fromJSON(JSONObject jsonObject){
        setHz(jsonObject.getDouble("HZ"));
        setZglys(jsonObject.getDouble("ZGLYS"));
        setZszgl(jsonObject.getDouble("ZSZGL"));
        setZxygzdl(jsonObject.getDouble("ZXYGZDL"));

        setIc(jsonObject.getDouble("Ic"));
        setIb(jsonObject.getDouble("Ib"));
        setIa(jsonObject.getDouble("Ia"));

        setVc(jsonObject.getDouble("Vc"));
        setVb(jsonObject.getDouble("Vb"));
        setVa(jsonObject.getDouble("Va"));

        Integer h = jsonObject.getInteger("RunTime_H");
        Integer m = 0;
        Integer s = 0;
        Integer ms = jsonObject.getInteger("RunTime_M_S");
        String ss = Integer.toHexString(ms);
        if (ss.length() <= 2){
            s = Integer.valueOf(ss,16);
        }else{
            String sStr = ss.substring(ss.length()-2,ss.length());
            s = Integer.valueOf(sStr,16);

            String mStr = ss.substring(0,ss.length()-2);
            m = Integer.valueOf(mStr,16);
        }
        s = h*3600+m*60+s;
        setRuntime(s);
    }


}
